package Test6.Operation;

import Test6.BOOK.Book;
import Test6.BOOK.BookList;

import java.util.Scanner;

public class AddOperation implements IOperatopn{
    public void work(BookList bookList){
        System.out.println("请输入要加入的图书数量:");
        Scanner s= new Scanner(System.in);
        int n =s.nextInt();
        s.nextLine();
        int m = bookList.getUsedSize();
        if(n+m<=10){
            Book[] books = new Book[n];
            System.out.println("请输入要加入的图书:");
            for (int j = 0; j < n; j++) {
                books[j] =new Book();
            }
            for (int i = 0; i < n; i++) {
                System.out.println("请输入书籍名称:");
                books[i].setName(s.nextLine());
                for (int j = 0; j < m; j++) {
                    if(books[i].getName().compareTo(bookList.getBooks(j).getName())==0) {
                        System.out.println("重复输入!请重新输入书籍名称:");
                        books[i].setName(s.nextLine());
                    }
                }
                System.out.println("请输入书籍作者:");
                books[i].setAuthor(s.nextLine());
                System.out.println("请输入书籍价格:");
                books[i].setPrice(s.nextInt());
                s.nextLine();
                System.out.println("请输入书籍类型:");
                books[i].setType(s.nextLine());
                bookList.setBooks(i+m,books[i]);
                m++;
            }
            bookList.setUsedSize(m);
        }else {
            System.out.println("存储空间不够,即将退出程序!");
            System.exit(0);
        }
        new OutSystem().outSystem();
    }
}
